package loveqq.niceexcel.read.builder;

import loveqq.niceexcel.converter.Converter;
import loveqq.niceexcel.read.ExcelReader;
import loveqq.niceexcel.read.ReadConfig;
import loveqq.niceexcel.read.handler.ReadHandler;
import lombok.Getter;

import java.io.InputStream;
import java.util.ArrayList;

/**
 * @author zhongjh@tsintergy.com
 * @date 2022-08-23
 */
@Getter
class ReadConfigReaderBuilder<THIS> {
    protected final ReadConfig readConfig;

    protected ReadConfigReaderBuilder() {
        this.readConfig = new ReadConfig();
        this.readConfig.setReadHandlerList(new ArrayList<>());
        this.readConfig.setConverterList(new ArrayList<>());
    }

    public ExcelReader build() {
        return new ExcelReader(readConfig);
    }

    public THIS file(InputStream inputStream) {
        this.readConfig.setInputStream(inputStream);
        return (THIS) this;
    }

    public THIS addReadHandler(ReadHandler readHandler) {
        this.readConfig.getReadHandlerList().add(readHandler);
        return (THIS) this;
    }

    public THIS addConverter(Converter<?> converter) {
        this.readConfig.getConverterList().add(converter);
        return (THIS) this;
    }

}
